var src = new Array(4);
var count = 0;
var trueCount = 0;
var outPut = '';
/**
 *
 *
 * @param {*} arr
 */
function getOneCalc(arr, step) {
    step = step || [];
    for (let i = 0; i < arr.length; i++) {
        for (let j = i + 1; j < arr.length; j++) {
            /** 
             * 0 a+b
             * 1 a-b
             * 2 b-a
             * 3 a*b
             * 4 a/b
             * 5 b/a
             */                     
            for (let z = 0; z < 6; z++) {
                let newVal;
                let newArr = getOtherNum(arr, i, j);
                let newStep = JSON.parse(JSON.stringify(step));
                if (z == 0) {
                    newVal = Number(arr[i]) + Number(arr[j]);
                    newStep.push(arr[i] + '+' + arr[j]);
                }
                if (z == 1) {
                    newVal = arr[i] - arr[j];
                    newStep.push(arr[i] + '-' + arr[j]);
                }
                if (z == 2) {
                    newVal = arr[j] - arr[i];
                    newStep.push(arr[j] + '-' + arr[i]);
                }
                if (z == 3) {
                    newVal = arr[i] * arr[j];
                    newStep.push(arr[i] + '*' + arr[j]);
                }
                if (z == 4) {
                    newVal = arr[i] / arr[j];
                    newStep.push(arr[i] + '/' + arr[j]);
                }
                if (z == 5) {
                    newVal = arr[j] / arr[i];
                    newStep.push(arr[j] + '/' + arr[i]);
                }
                newArr.push(newVal);
                if (newArr.length !== 1) {
                    getOneCalc(newArr, newStep)
                } else {
                    if (newArr[0] === 24) {
                        ++count;
                        console.log(++trueCount, 'success', newArr[0], newStep);
                        if (outPut != undefined) {
                            outPut += '\n' + newStep.join('>');
                        }
                    } else {
                        ++count;
                        // console.log(++count, newArr[0]);
                    }
                    if (count == 3888) {
                        if (outPut != undefined) {
                            outPut += '\n' + new Date().toLocaleString() + '结束，共' + trueCount + '种结果';
                        }
                    }
                }
            }
        }
    }
}
// getOneCalc([4,1,1,8])
// getOneCalc([11,10,11,2])

function getOtherNum(arr, i, j) {
    let _arr = []
    for (let z = 0; z < arr.length; z++) {
        if (z!=i && z!=j) {
            _arr.push(arr[z]);
        }
    }
    return _arr;
}